/**
 * 添加或者修改页面
 */
var CleanRuleInfoDlg = {
    data: {
        dataCleanRuleId: "",
        dataCleanRuleNumber: "",
        dataCleanRuleName: "",
        dataIsDelete: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload', 'formSelects', 'layer'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    $("#dataIsDelete").val(1)


    /**
     * 表单长度校验
     */
    $("#dataCleanRuleNumber").blur(function () {
        let number = $("#dataCleanRuleNumber").val()
        let arr = number.split("")
        // console.log(arr)
        if (arr.length > 11) {
            layer.msg("规则编码长度不能超过11位")
            let newNumber = arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5] + arr[6] + arr[7] + arr[8] + arr[9] + arr[10];
            $("#dataCleanRuleNumber").val(newNumber)
            // console.log(newNumber)
        }
    })
    $("#dataCleanRuleName").blur(function () {
        let number = $("#dataCleanRuleName").val()
        let arr = number.split("")
        // console.log(arr)
        if (arr.length > 11) {
            layer.msg("规则名称长度不能超过20位")
            let newNumber = arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5] + arr[6] + arr[7] + arr[8] + arr[9] + arr[10] + arr[11] + arr[12] + arr[13] + arr[14] + arr[15] + arr[16] + arr[17] + arr[18] + arr[19];
            $("#dataCleanRuleName").val(newNumber)
            // console.log(newNumber)
        }
    })




    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/cleanRule/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});